import axios from 'axios'
import { Message } from 'element-ui'
// import { checkoutToken, removeTokenFormStorage } from '@/utils/storage'
import store from '@/store'
// import router from '@/router'

export const request = axios.create({
  baseURL: 'http://big-event-vue-api-t.itheima.net',
  timeout: 5000
})

request.interceptors.request.use(config => {
  config.headers.Authorization = store.getters.token
  return config
}, error => {
  return Promise.reject(new Error(error))
})

request.interceptors.response.use(response => {
  if (response.data.code !== 0) {
    Message.error(response.data.message)
    return Promise.reject(new Error(response.data))
  }
  return response.data
}, error => {
  return Promise.reject(new Error(error))
})
